// SETUP

#include intrographics.txt
#include ladyluckbiggraphics.txt

setdatapath("data/graphics/cutscenes/robot/");

var robotgraphics = {
	idle: {
		animation: "robot_idle.json",
		pack: "robot.pck",
		loop: true
	},
	worried_idle: {
		animation: "robot_worried_idle.json",
		pack: "robot.pck",
		loop: true
	},
	transform: {
		animation: "robot_transform.json",
		pack: "robot.pck",
		speed: 2,
		loop: false
	}
}
var robot = addsprite("robot", 1, robotgraphics);

// HELPER FUNCTIONS	

function signanimate(sign) {
	var s = sign.show("turn");
	//s.onComplete(function() { resume(); sign.show("loop"); });
	//pause();
	while(!s.completed) {
		// do nothing
	}
	sign.show("loop");
}

function fadein_sprite(sprite, time) {
	return;
	sprite.alpha = 0.0;
	Actuate.tween(sprite, time, { alpha: 1.0 });
	wait(time);
}

function fadeout_sprite(sprite, time) {
	return;
	Actuate.tween(sprite, time, { alpha: 0.0 });
	wait(time);
}

var fade_time = 0.4;

// ACTORS

actor("Lady Luck", screenwidthmid + 800, 550, Col.YELLOW, CENTER, BOTTOM, "chat_ladyluck", "characters/misc/charicon_ladyluck");
actor("Robot", 2600, 600, 0xDDDDDD, RIGHT, TOP, "chat_robot", "characters/robot/charicon_robot");
// INTRO

play("music_cutscene_cheery");

changebackground("intro_sign");

sign.y = -screenheight;
ladyluck_sign.y = -screenheight;
sign.show("loop");
ladyluck_sign.show("idle");

Actuate.tween(sign, 2, { y: 0 }).ease(Expo.easeOut);
Actuate.tween(ladyluck_sign, 2, { y: 0 }).ease(Expo.easeOut);

wait(0.5);

fadein();
play("cutscene_audience");

wait(1.5);

ladyluck_sign.show("talking", true);
speak("Lady Luck", "Our next contestant works hard, plays hard,|and most importantly: tries hard.");
speak("Lady Luck", "Some might say TOO hard?", "thinking");
speak("Lady Luck", "...but that’s not our place to judge!", "sly");
speak("Lady Luck", "Instead, let’s give a warm welcome to...");
ladyluck_sign.show("idle", true);

fadeout();
while(isfading()) {
	// do nothing
}
changebackground("intro_transform");
sign.hide();
ladyluck_sign.hide();
fadein();

robot.x = screenwidth;
var transform = robot.show("transform");
Actuate.tween(robot, 2, { x: 0 }).ease(Expo.easeOut);

var marker_human = false;
var marker_dice = false;
while(true) {	
	if(!marker_human && transform.marker == "human") {
		marker_human = true;
		transform.paused = true;
    speak("Lady Luck", "... the Robot!");
    play("transformintodice");
		transform.paused = false;
	} else if(!marker_dice && transform.marker == "dice") {
		marker_dice = true;
		transform.paused = true;
    actor("Robot", screenwidthmid, screenheightmid - 300, 0xDDDDDD, CENTER, BOTTOM, "chat_robot", "characters/robot/charicon_robot");
    speak("Robot", "Woo! Here we go!", "personality");
    fadeout();
	  break;
	}
}

while(isfading()) {
	// do nothing
}

robot.scale = 0.5;
robot.x = 2700 - ((robot.getwidth("idle") * robot.scale) / 2);
robot.y = 800;
changebackground("intro_stage");
fadein();
robot.show("idle");

ladyluck_big.x = -screenwidth;
ladyluck_big.show("idle");
Actuate.tween(ladyluck_big, 2, { x: 0 }).ease(Expo.easeOut);

play("cutscene_audience");

actor("Robot", 2600, 780, 0xDDDDDD, CENTER, BOTTOM, "chat_robot", "characters/robot/charicon_robot");
speak("Robot", "Thank you, Lady Luck!");
speak("Robot", "I’m really excited to begin this|journey to a better self!");

ladyluck_big.show("talking", true);
actor("Lady Luck", screenwidthmid + 240, screenheightmid - 240, Col.YELLOW, RIGHT, BOTTOM, "chat_ladyluck", "characters/misc/charicon_ladyluck");
speak("Lady Luck", "And what do you hope to win?");
ladyluck_big.show("idle", true);

speak("Robot", "I want to eliminate my need to sleep.");

ladyluck_big.show("talking-sly", true);
actor("Lady Luck", screenwidthmid + 240, screenheightmid - 280, Col.YELLOW, RIGHT, BOTTOM, "chat_ladyluck", "characters/misc/charicon_ladyluck");
speak("Lady Luck", "... uh, I'm sorry?", "sly");
ladyluck_big.show("idle-sly", true);

speak("Robot", "With an extra eight hours a day, I can|truly become the best 'me' I can be!");

ladyluck_big.show("talking-thinking", true);
actor("Lady Luck", screenwidthmid + 240, screenheightmid - 280, Col.YELLOW, RIGHT, BOTTOM, "chat_ladyluck", "characters/misc/charicon_ladyluck");
speak("Lady Luck", "Why not just play for immortality?", "thinking");
speak("Lady Luck", "Then you’d have all the time in the world.", "thinking");
ladyluck_big.show("idle-thinking", true);

speak("Robot", "All the research shows that personal change is|more sustainable if you start small.");
speak("Robot", "I’m gonna try for immortality next time!");

ladyluck_big.show("talking-sly", true);
actor("Lady Luck", screenwidthmid + 240, screenheightmid - 280, Col.YELLOW, RIGHT, BOTTOM, "chat_ladyluck", "characters/misc/charicon_ladyluck");
speak("Lady Luck", "Oh my dear!", "sly");
ladyluck_big.show("talking", true);
actor("Lady Luck", screenwidthmid + 240, screenheightmid - 240, Col.YELLOW, RIGHT, BOTTOM, "chat_ladyluck", "characters/misc/charicon_ladyluck");
speak("Lady Luck", "There won't be a next time.", "scary");
speak("Lady Luck", "Just try to make the most of this one. In you go!");
ladyluck_big.show("idle", true);

play("cutscene_audience");

startgamefromcutscene();